home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 115_01.zip / CONFIG1.C < prev    next >
Text File  |  1993-06-01  |  15KB  |  739 lines

  1. /* Screen editor:  configuration program
  2.  *
  3.  * Source:  config1.c
  4.  * Version: June 4, 1981.
  5.  */
  6.  
  7. /* Values of control keys go here */
  8.  
  9. int up;            /* value of cursor up key */
  10. int down;        /* cursor down key */
  11. int left;        /* cursor left key */
  12. int right;        /* cursor right key */
  13. int ins;        /* enter insert mode key */
  14. int del;        /* delete character key */
  15. int esc;        /* leave current mode key */
  16. int abt;        /* undo editing key */
  17. int altup;        /* alternate up key */
  18. int altdn;        /* alternate down key */
  19. int delline;        /* delete line key */
  20. int govid;        /* enter video mode key */
  21.  
  22. /* Video screen  and printer characteristics go here */
  23.  
  24. int scrnl;        /* number of rows on screen */
  25. int scrnw;        /* # of columns on screen */
  26. int haseol;        /* has erase to end of line */
  27. int hasel;        /* has erase line */
  28. int hassup;        /* has hardware scroll up */
  29. int hassdn;        /* has hardware scroll down */
  30. int lwidth;        /* width of list device */
  31.  
  32. /* Define array which contains the code that the
  33.  * user gives to do special screen functions.
  34.  */
  35.  
  36. #define BYTEMAX    1000    /* size of byte array */
  37. char bytes[BYTEMAX];
  38. int bytec;        /* index of next free entry */
  39.  
  40. /* Define indices into bytes[] which point at start
  41.  * of code for each special screen function.
  42.  */
  43.  
  44. int gotoind;        /* index to gotoxy code */
  45. int eolind;        /* erase to end of line */
  46. int elind;        /* erase line */
  47. int supind;        /* scroll up */
  48. int sdnind;        /* scroll down */
  49.  
  50. /* Define return codes */
  51.  
  52. #define    YES    1    /* all ok */
  53. #define NO    2    /* try again */
  54. #define EXIT    3    /* stop the program */
  55.  
  56. /* Define special characters */
  57.  
  58. #define CR    13    /* carriage return */
  59. #define LF    10    /* line feed */
  60. #define    TAB    9    /* tab */
  61.  
  62. /* define output file index */
  63.  
  64. int    output;
  65.  
  66. /* This program has 5 parts.
  67.  *
  68.  * Part 1 asks which keys do which special functions.
  69.  * Part 2 asks which special functions the screen has.
  70.  * Part 3 asks what code sequences must be output
  71.  *        to the screen to do the functions in part 2.
  72.  * Part 4 creates the file ed1.ccc from the answers to
  73.  *        Part 1.
  74.  * Part 5 creates the file ed6.ccc from the answers to
  75.  *        Parts 2 and 3.
  76.  */
  77.  
  78. main()
  79. {
  80.     /* initialize byte count */
  81.     bytec=0;
  82.     /* sign on and give general information */
  83.     signon();
  84.     /* get keyboard information */
  85.     while (part1()==NO) {
  86.         ;
  87.     }
  88.     /* get screen features */
  89.     while (part2()==NO) {
  90.         ;
  91.     }
  92.     /* get control sequences for screen features */
  93.     while (part3()==NO) {
  94.         ;
  95.     }
  96.     /* make sure we want to continue */
  97.     blank();
  98.     plc("You are now ready to create files ");
  99.     pc("ed1.ccc and ed6.ccc.");
  100.     plc("Do you want to proceed ?");
  101.     if (yesno()==NO) {
  102.         return;
  103.     }
  104.     /* write keyboard info to file ed1.ccc */
  105.     if (part4()!=YES) {
  106.         return;
  107.     }
  108.     /* write control sequences for screen features
  109.      * to file ed6.ccc
  110.      */
  111.     part5();
  112.     /* sign off and tell about compiling */
  113.     signoff();
  114. }
  115.  
  116. /* sign on and tell how to abort */
  117.  
  118. signon()
  119. {
  120. plc("Welcome to the configuration program for the ");
  121. pc("screen editor.");
  122. plc("Hit control-c to exit this program early.");
  123. plc("Hit control-p to send output to the printer.");
  124. }
  125.  
  126. /* part 1.  find out what keys will be used for
  127.  *          special functions.
  128.  */
  129.  
  130. part1()
  131. {
  132.  
  133. blank();
  134. plc("This section deals with your keyboard.");
  135. plc("For each function key, enter the DECIMAL ");
  136. pc("value of the ascii ");
  137. plc("code that you want to assign to that function key.");
  138. plc("Hit carriage return to indicate the default value.");
  139.  
  140. blank();
  141. plc("up key:");
  142. indent();
  143. pc("This key usually moves the cursor up.  In insert mode");
  144. indent();
  145. pc("this key inserts a line above the current line.");
  146. indent();
  147. pc("The default is line feed (10).");
  148. up=getval(10);
  149.  
  150. plc("down key:");
  151. indent();
  152. pc("This key usually moves the cursor down.  In insert mode");
  153. indent();
  154. pc("this key inserts a line below the current line.");
  155. indent();
  156. pc("The default is carriage return (13).");
  157. down=getval(13);
  158.  
  159. plc("alternate up key:");
  160. indent();
  161. pc("This key usually inserts a line above the current line.");
  162. indent();
  163. pc("In insert mode it just moves the cursor up");
  164. indent();
  165. pc("The default is control-u (21).");
  166. altup=getval(21);
  167.  
  168. plc("alternate down key:");
  169. indent();
  170. pc("This key usually inserts a line below the current line.");
  171. indent();
  172. pc("In insert mode it just moves the cursor down");
  173. indent();
  174. pc("The default is control-d (4).");
  175. altdn=getval(4);
  176.  
  177. plc("left key:");
  178. indent();
  179. pc("This key moves the cursor left ");
  180. pc("in all edit modes.");
  181. indent();
  182. pc("The default is back space (8).");
  183. left=getval(8);
  184.  
  185. plc("right key:");
  186. indent();
  187. pc("This key moves the cursor right ");
  188. pc("in all edit modes.");
  189. indent();
  190. pc("The default is control-r (18).");
  191. right=getval(18);
  192.  
  193. plc("insert key:");
  194. indent();
  195. pc("This key enters insert mode.");
  196. indent();
  197. pc("The default is control-n (14).");
  198. ins=getval(14);
  199.  
  200. plc("video key:");
  201. indent();
  202. pc("This key enters video mode.");
  203. indent();
  204. pc("The default is control-v (22).");
  205. govid=getval(22);
  206.  
  207. plc("exit current mode key:");
  208. indent();
  209. pc("This key exits the current mode.");
  210. indent();
  211. pc("The default is esc (27).");
  212. esc=getval(27);
  213.  
  214. plc("delete character key:");
  215. indent();
  216. pc("This key deletes the character to the left ");
  217. pc("of the cursor.");
  218. indent();
  219. pc("The default is del (127).");
  220. del=getval(127);
  221.  
  222. plc("delete line key:");
  223. indent();
  224. pc("This key deletes the line on which the cursor rests.");
  225. indent();
  226. pc("The default is control-z (26).");
  227. delline=getval(26);
  228.  
  229. plc("abort key:");
  230. indent();
  231. pc("This key undoes the editing done on a line.");
  232. indent();
  233. pc("The default is control-x (24).");
  234. abt=getval(24);
  235.  
  236. /* recap what the user has typed.
  237.  * ask if everything is all right.
  238.  */
  239.  
  240. plc("The values of the keyboard keys are:");
  241. plc("up:           ");
  242. putdec(up,3);
  243. plc("down:         ");
  244. putdec(down,3);
  245. plc("alternate up: ");
  246. putdec(altup,3);
  247. plc("alt down:     ");
  248. putdec(altdn,3);
  249. plc("left:         ");
  250. putdec(left,3);
  251. plc("right:        ");
  252. putdec(right,3);
  253. plc("insert move:  ");
  254. putdec(ins,3);
  255. plc("video mode:   ");
  256. putdec(govid,3);
  257. plc("exit mode:    ");
  258. putdec(esc,3);
  259. plc("delete char:  ");
  260. putdec(del,3);
  261. plc("delete line:  ");
  262. putdec(delline,3);
  263. plc("abort:        ");
  264. putdec(abt,3);
  265.  
  266. blank();
  267. plc("are all values correct ?");
  268. return(yesno());
  269. }
  270.  
  271. /* get features of the video screen */
  272.  
  273. part2()
  274. {
  275.  
  276. blank();
  277. plc("This section deals with the video screen.");
  278. plc("The screen MUST have a cursor positioning function,");
  279. plc("but no other special screen functions are required.");
  280.  
  281. blank();
  282. plc("screen length:");
  283. indent();
  284. pc("How many rows does your screen have ?");
  285. indent();
  286. pc("The default is 16.");
  287. scrnl=getval(16);
  288.  
  289. blank();
  290. plc("screen width:");
  291. indent();
  292. pc("How many columns does your screen have ?");
  293. indent();
  294. pc("The default is 64.");
  295. scrnw=getval(64);
  296.  
  297. blank();
  298. plc("printer width:");
  299. indent();
  300. pc("How many columns does your printer have ?");
  301. indent();
  302. pc("The default is 132.");
  303. lwidth=getval(132);
  304.  
  305. blank();
  306. plc("erase line:");
  307. indent();
  308. pc("Does your screen have a function which erases ");
  309. indent();
  310. pc("the line on which the cursor rests ?");
  311. hasel=yesno();
  312.  
  313. plc("erase to end of line:");
  314. indent();
  315. pc("Does your screen have a function which erases ");
  316. indent();
  317. pc("from the cursor to the end of the line ?");
  318. haseol=yesno();
  319.  
  320. plc("hardware scroll up: (line feed)");
  321. indent();
  322. pc("Does your screen have a function that scrolls the");
  323. indent();
  324. pc("screen up when the cursor is on the bottom line ?");
  325. hassup=yesno();
  326.  
  327. plc("hardware scroll down:");
  328. indent();
  329. pc("Does your screen have a function which scrolls the");
  330. indent();
  331. pc("screen down when the cursor is on the top line ?");
  332. hassdn=yesno();
  333.  
  334. blank();
  335. plc("You have answered as follows: ");
  336. plc("screen length:            ");
  337. putdec(scrnl,1);
  338. plc("screen width:             ");
  339. putdec(scrnw,1);
  340. plc("printer width:            ");
  341. putdec(lwidth,1);
  342. plc("erase line ?              ");
  343. putyesno(hasel);
  344. plc("erase to end of line ?    ");
  345. putyesno(haseol);
  346. plc("hardware scroll up ?      ");
  347. putyesno(hassup);
  348. plc("hardware scroll down ?    ");
  349. putyesno(hassdn);
  350.  
  351. blank();
  352. plc("are all these values correct ?");
  353. return(yesno());
  354. }
  355.  
  356. part3()
  357. {
  358. blank();
  359. plc("This section asks you to supply code sequences for");
  360. plc("the special functions that you said your screen had.");
  361. plc("Enter each sequence one byte at a time.");
  362. plc("End the sequence by typing just a carriage return.");
  363. plc("Indicate each byte by giving a character expression.");
  364. blank();
  365. plc("Hit any character to get more instructions.");
  366. getchar();
  367.  
  368. blank();
  369. plc("An expression consists of terms separated by + or -.");
  370. plc("Each term is either:");
  371. plc("1.  a decimal number or");
  372. plc("2.  an ascii character in single quotes or");
  373. plc("3.  the letters x or y without quotes.");
  374. plc("Use x and y only for the goto xy code sequence.");
  375. plc("The x and y represent the desired cursor coordinates.");
  376. plc("For example, a common sequence for goto x y is:");
  377. plc("   27, '=', x+32, y+32");
  378.  
  379. blank();
  380. plc("goto x y:");
  381. indent();
  382. pc("Enter code to position the cursor at column x and row y.");
  383. indent();
  384. pc("0,0 is the top left corner of the screen.");
  385. getbytes(&gotoind);
  386.  
  387. blank();
  388. if (hasel==YES) {
  389.  
  390. plc("erase line:");
  391. indent();
  392. pc("Enter code to erase the line on which the ");
  393. pc("cursor rests.");
  394. getbytes(&elind);
  395.  
  396. }
  397.  
  398. blank();
  399. if (haseol==YES) {
  400.  
  401. plc("erase to end of line:");
  402. indent();
  403. pc("Enter code to erase from the cursor to the ");
  404. pc("end of the line.");
  405. getbytes(&eolind);
  406.  
  407. }
  408.  
  409. blank();
  410. if (hassup==YES) {
  411.  
  412. plc("hardware scroll up: (line feed)");
  413. indent();
  414. pc("Enter code to scroll the screen up assuming ");
  415. indent();
  416. pc("the cursor is on the bottom line.");
  417. getbytes(&supind);
  418.  
  419. }
  420.  
  421. blank();
  422. if (hassdn==YES) {
  423.  
  424. plc("hardware scroll down:");
  425. indent();
  426. pc("Enter code to scroll the screen down assuming ");
  427. indent();
  428. pc("that the cursor is on the top line.");
  429. getbytes(&sdnind);
  430.  
  431. }
  432.  
  433. }
  434.  
  435. part4()
  436. {
  437.  
  438. if ((output=fopen("ed1.ccc","w"))==0) {
  439.     plc("open error on ed1.ccc");
  440.     return(EXIT);
  441. }
  442.  
  443. comment();
  444. plf("Screen editor:  special key definitions");
  445. plf("Source:  ed1.ccc");
  446. plf("This file was created by the configuration program");
  447. endcom();
  448.  
  449. blankf();
  450. comment();
  451. plf("Define which keys are used for special edit functions.");
  452. endcom();
  453.  
  454. blankf();
  455. putdef("UP1",up);
  456. putdef("DOWN1",down);
  457. putdef("UP2",altup);
  458. putdef("DOWN2",altdn);
  459. putdef("LEFT1",left);
  460. putdef("RIGHT1",right);
  461. putdef("INS1",ins);
  462. putdef("VID1",govid);
  463. putdef("ESC1",esc);
  464. putdef("DEL1",del);
  465. putdef("ZAP1",delline);
  466. putdef("ABT1",abt);
  467.  
  468. blankf();
  469. comment();
  470. plf("Define length and width of screen and printer.");
  471. endcom();
  472.  
  473. blankf();
  474. putdef("SCRNW",scrnw);
  475. putdef("SCRNW1",scrnw-1);
  476. putdef("SCRNL",scrnl);
  477. putdef("SCRNL1",scrnl-1);
  478. putdef("SCRNL2",scrnl-2);
  479. putdef("LISTW",lwidth);
  480. blankf();
  481.  
  482. fclose(output);
  483. return(YES);
  484. }
  485.  
  486. part5()
  487. {
  488.  
  489. if ((output=fopen("ed6.ccc","w"))==0) {
  490.     plc("Open error on ed6.ccc");
  491.     return(EXIT);
  492. }
  493.  
  494. comment();
  495. plf("Screen editor:  terminal output module");
  496. plf("Source:  ed6.ccc");
  497. plf("This file was created by the configuration ");
  498. pf("program.");
  499. endcom();
  500.  
  501. blankf();
  502. comment();
  503. plf("Define the current coordinates of the cursor.");
  504. endcom();
  505.  
  506. blankf();
  507. plf("int outx, outy;");
  508.  
  509. blankf();
  510. comment();
  511. plf("Return the current coordinates of the cursor.");
  512. endcom();
  513.  
  514. blankf();
  515. plf("outgetx()");
  516. beginf();
  517. tab1f(); pf("return(outx);");
  518. endf();
  519.  
  520. blankf();
  521. plf("outgety()");
  522. beginf();
  523. tab1f(); pf("return(outy);");
  524. endf();
  525.  
  526. blankf();
  527. comment();
  528. plf("Output one printable character to the screen.");
  529. endcom();
  530.  
  531. blankf();
  532. plf("outchar(c) char c;");
  533. beginf();
  534. tab1f(); pf("syscout(c);");
  535. tab1f(); pf("outx++;");
  536. tab1f(); pf("return(c);");
  537. endf();
  538.  
  539. blankf();
  540. comment();
  541. plf("Position cursor to position x,y on screen.");
  542. plf("0,0 is the top left corner.");
  543. endcom();
  544.  
  545. blankf();
  546. plf("outxy(x,y) int x,y;");
  547. beginf();
  548. tab1f(); pf("outx=x;");
  549. tab1f(); pf("outy=y;");
  550. putbytes(gotoind);
  551. endf();
  552.  
  553. blankf();
  554. comment();
  555. plf("Erase the entire screen.");
  556. plf("Make sure the rightmost column is erased.");
  557. endcom();
  558.  
  559. blankf();
  560. plf("outclr()");
  561. if ((hasel==YES)+(haseol==YES)) {
  562.  
  563. beginf();
  564. plf("int k;");
  565. tab1f(); pf("k=0;");
  566. tab1f(); pf("while (k<SCRNL) {");
  567. tab2f(); pf("outxy(0,k++);");
  568. tab2f(); pf("outdelln();");
  569. tab1f(); pf("}");
  570. tab1f(); pf("outxy(0,0);");
  571. endf();
  572.  
  573. }
  574. else {
  575.  
  576. beginf();
  577. plf("int k;");
  578. tab1f(); pf("outxy(0,0);");
  579. tab1f(); pf("k=SCRNL*SCRNW;");
  580. tab1f(); pf("while ((k--)>0) {");
  581. tab2f(); pf("syscout(' ');");
  582. tab1f(); pf("}");
  583. tab1f(); pf("outxy(0,0);");
  584. endf();
  585.  
  586. } /* end else */
  587.  
  588. blankf();
  589. comment();
  590. plf("Delete the line on which the cursor rests.");
  591. plf("Leave the cursor at the left margin.");
  592. endcom();
  593.  
  594. blankf();
  595. plf("outdelln()");
  596. if (hasel==YES) {
  597.  
  598. beginf();
  599. putbytes(elind);
  600. endf();
  601.  
  602. }
  603. else {
  604.  
  605. beginf();
  606. tab1f(); pf("outxy(0,outy);");
  607. tab1f(); pf("outdeol();");
  608. endf();
  609.  
  610. }
  611.  
  612. blankf();
  613. comment();
  614. plf("Delete to end of line.");
  615. plf("Assume the last column is blank.");
  616. endcom();
  617.  
  618. blankf();
  619. plf("outdeol()");
  620. if (haseol==YES) {
  621.  
  622. beginf();
  623. putbytes(eolind);
  624. endf();
  625.  
  626. }
  627. else {
  628.  
  629. beginf();
  630. plf("int k;");
  631. tab1f(); pf("k=outx;");
  632. tab1f(); pf("while (k++<SCRNW1) {");
  633. tab2f(); pf("syscout(' ');");
  634. tab1f(); pf("}");
  635. tab1f(); pf("outxy(outx,outy);");
  636. endf();
  637.  
  638. }
  639.  
  640. blankf();
  641. comment();
  642. plf("Return yes if terminal has indicated hardware scroll.");
  643. endcom();
  644.  
  645. blankf();
  646. plf("outhasup()");
  647. beginf();
  648. tab1f();
  649. if (hassup==YES) {
  650.     pf("return(YES);");
  651. }
  652. else {
  653.     pf("return(NO);");
  654. }
  655. endf();
  656.  
  657. blankf();
  658. plf("outhasdn()");
  659. beginf();
  660. tab1f();
  661. if (hassdn==YES) {
  662.     pf("return(YES);");
  663. }
  664. else {
  665.     pf("return(NO);");
  666. }
  667. endf();
  668.  
  669. blankf();
  670. comment();
  671. plf("Scroll the screen up.");
  672. plf("Assume the cursor is on the bottom line.");
  673. endcom();
  674.  
  675. blankf();
  676. plf("outsup()");
  677. if (hassup==YES) {
  678.  
  679. beginf();
  680. tab1f(); pf("/* auto scroll */");
  681. tab1f(); pf("outxy(0,SCRNL1);");
  682. putbytes(supind);
  683. endf();
  684.  
  685. }
  686. else {
  687.  
  688. beginf();
  689. endf();
  690.  
  691. }
  692.  
  693. blankf();
  694. comment();
  695. plf("Scroll screen down.");
  696. plf("Assume the cursor is on the top line.");
  697. endcom();
  698.  
  699. blankf();
  700. plf("outsdn()");
  701. if (hassdn==YES) {
  702.  
  703. beginf();
  704. tab1f(); pf("/* auto scroll */");
  705. tab1f(); pf("outxy(0,0);");
  706. putbytes(sdnind);
  707. endf();
  708.  
  709. }
  710. else {
  711.  
  712. beginf();
  713. endf();
  714.  
  715. }
  716.  
  717. /* make sure last line ends with CR */
  718. plf("");
  719. fclose(output);
  720. return(YES);
  721. }
  722.  
  723. signoff()
  724. {
  725. plc("The configuration process is now complete.");
  726. plc("You are now ready to compile the screen editor.");
  727. return(YES);
  728. }
  729.  
  730. eturn(NO);");
  731. }
  732. endf();
  733.  
  734. blankf();
  735. plf("outhasdn()");
  736. beginf();
  737. tab1f();
  738. if (hassdn==YES) {
  739.     pf("return(YES